/**
 * 漆水河 脚手架基础公开课
 * 2022/8/13 --- 2022/12/13
 * 有疑问可加QQ群: 809126489，后续会持续输出与大家一起成长
 */
package com.qishuihe.common.application.upload;

import com.qishuihe.common.infrastructure.upload.UpLoadService;
import com.qishuihe.baseinterface.basevo.vo.ResultVO;
import com.qishuihe.outbound.upload.FIleVO;
import com.qishuihe.outbound.upload.IUpLoad;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/common")
public class UploadControl implements IUpLoad {


    @Autowired
    private UpLoadService upLoadServiceImpl;
    @Override
    @PostMapping(value ="/upLoadFiles",headers={"content-type=multipart/form-data"})
    public ResultVO<List<FIleVO>> upLoadFiles(@RequestPart("files") MultipartFile[] files) {
        ResultVO<List<FIleVO>> resultDto = new ResultVO<>();
        resultDto= upLoadServiceImpl.upLoadFiles(files);
        return resultDto;
    }

    @Override
    @PostMapping("/downLoadFiles")
    public void downLoadFiles(HttpServletResponse response,@RequestBody List<String> fileIds) throws IOException {
        upLoadServiceImpl.downLoadFiles(response,fileIds);
    }
}
